24 #define foreach(x, v) for (typeof (v).begin() x=(v).begin(); x !=(v).end(); ++x)
25 #define For(i, a, b) for (int i=(a); i<(b); ++i)
26 #define D(x) cout << #x " is " << x << endl
28 const double EPS
= 1e-9;
29 int cmp(double x
, double y
= 0, double tol
= EPS
) {
30 return (x
<= y
+ tol
) ? (x
+ tol
< y
) ? -1 : 0 : 1;
33 const int MAXN
= 100001;
37 int f(int node
, bool edge
, int parent
= -1) {
38 assert(g
[node
].size() > 0);
39 if (g
[node
].size() == 1 and g
[node
][0] == parent
) { // Base case
43 if (memo
[node
][edge
] > -1) return memo
[node
][edge
];
47 for (int k
= 0; k
< g
[node
].size(); ++k
) {
49 if (v
== parent
) continue;
50 ans
+= f(v
, true, node
);
54 // do not take this node
56 for (int k
= 0; k
< g
[node
].size(); ++k
) {
58 if (v
== parent
) continue;
59 option
+= f(v
, false, node
);
61 ans
= min(ans
, option
);
64 return memo
[node
][edge
] = ans
;
68 int n
; scanf("%d", &n
);
69 for (int i
= 0; i
< n
; ++i
) {
71 memo
[i
][0] = memo
[i
][1] = -1;
73 for (int i
= 0; i
< n
- 1; ++i
) {
74 int u
, v
; scanf("%d %d", &u
, &v
);
82 printf("%d\n", min(f(0, false), f(0, true)));